# Group Discount Codes
Discount Codes related to the events.

| Parameter | Description | Type | Required |
|:----------|-------------|------|----------|
| `code`  | Discount Code | string | **yes** |
| `discount-url` | URL of the discount | string | - |
| `value` | Value of the discount | float | **yes** |
| `type` | Amount or Percentage | string | **yes** |
| `is-active` | If the discount code is active | boolean | - |
| `tickets-number` | Tickets Number for Discount Code | integer (>=0) | - |
| `min-quantity` | Minimum number of tickets for Discount Code | integer (>=0) | - |
| `max-quantity` | Maximum number of tickets for Discount Code | integer | - |
| `valid-from` | Discount Code valid from | ISO 8601 (tz-aware) | - |
| `valid-till` | Discount Code valid till | ISO 8601 (tz-aware) | - |
| `created-at` | Discount Code created at | ISO 8601 (tz-aware) | - |
| `used-for` | Discount Code used for: tickets or events | String | **yes** |


## Event Discount Code Collection [/v1/discount-codes{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]
+ Parameters
    + page%5bsize%5d (optional, integer, `10`) - Maximum number of resources in a single paginated response.
    + page%5bnumber%5d (optional, integer, `2`) - Page number to fetched for the paginated response.
    + sort (optional, string, `code`) - Sort the resources according to the given attribute in ascending order. Append '-' to sort in descending order.
    + filter (optional, string, `[]`) - Filter according to the flask-rest-jsonapi filtering system. Please refer: http://flask-rest-jsonapi.readthedocs.io/en/latest/filtering.html for more.

### List All Event Discount Codes [GET]
Get a list of Discount Codes.

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
            "meta": {
                "count": 2
            },
            "data": [
                {
                    "relationships": {
                        "events": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/events",
                                "related": "/v1/discount-codes/1/events"
                            }
                        },
                        "event": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/event",
                                "related": "/v1/discount-codes/1/event"
                            }
                        }
                    },
                    "attributes": {
                        "code": "DC101",
                        "valid-from": "2099-06-18T18:30:00+00:00",
                        "min-quantity": 0,
                        "created-at": "2099-08-05T23:38:04.449623+00:00",
                        "tickets-number": 404,
                        "value": 100,
                        "max-quantity": 100,
                        "is-active": false,
                        "used-for": "event",
                        "deleted-at": null,
                        "valid-till": "2099-06-24T18:30:00+00:00",
                        "type": "amount",
                        "discount-url": "https://my-discount-url.com"
                    },
                    "type": "discount-code",
                    "id": 1,
                    "links": {
                        "self": "/v1/discount-codes/1"
                    }
                },
                {
                    "relationships": {
                        "event": {
                            "links": {
                                "self": "/v1/discount-codes/2/relationships/event",
                                "related": "/v1/discount-codes/2/event"
                            }
                        },
                        "tickets": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/tickets",
                                "related": "/v1/discount-codes/1/tickets"
                            }
                        }
                    },
                    "attributes": {
                        "code": "DC101",
                        "valid-from": "2099-06-18T18:30:00+00:00",
                        "min-quantity": 0,
                        "created-at": "2099-08-23T14:07:33.175725+00:00",
                        "tickets-number": 404,
                        "value": 100,
                        "max-quantity": 100,
                        "is-active": false,
                        "used-for": "ticket",
                        "deleted-at": null,
                        "valid-till": "2099-06-24T18:30:00+00:00",
                        "type": "amount",
                        "discount-url": "https://my-discount-url.com"
                    },
                    "type": "discount-code",
                    "id": 2,
                    "links": {
                        "self": "/v1/discount-codes/2"
                    }
                }
            ],
            "jsonapi": {
                "version": "1.0"
            },
            "links": {
                "self": "/v1/discount-codes"
            }
        }


### Create Event Discount Code [POST]
Create a new Discount Code for event. (Only Admin)

+ Request (application/vnd.api+json)

    + Headers

            Authorization: JWT <Auth Key>

    + Body

            {
              "data": {
                "attributes": {
                  "code": "DC101",
                  "discount-url": "https://my-discount-url.com",
                  "value": "100",
                  "type": "amount",
                  "is-active": "false",
                  "tickets-number": "404",
                  "min-quantity": "0",
                  "max-quantity": "100",
                  "valid-from": "2099-06-18T18:30:00+00:00",
                  "valid-till": "2099-06-24T18:30:00+00:00",
                  "used-for": "event"
                },
                "type": "discount-code",
                "relationships": {
                  "events": {
                    "data": [{
                      "id": "1",
                      "type": "event"
                    }]
                  }
                }
              }
            }

+ Response 201 (application/vnd.api+json)

        {
            "data": {
                "relationships": {
                    "event": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/event",
                            "related": "/v1/discount-codes/1/event"
                        }
                    }
                },
                "attributes": {
                    "code": "DC101",
                    "valid-from": "2017-06-18T18:30:00+00:00",
                    "min-quantity": 0,
                    "created-at": "2017-06-27T14:47:14.996906+00:00",
                    "tickets-number": 404,
                    "value": 100,
                    "max-quantity": 100,
                    "is-active": false,
                    "used-for": "event",
                    "deleted-at": null,
                    "valid-till": "2017-06-24T18:30:00+00:00",
                    "type": "amount",
                    "discount-url": "https://my-discount-url.com"
                },
                "type": "discount-code",
                "id": 4,
                "links": {
                    "self": "/v1/discount-codes/4"
                }
            },
            "jsonapi": {
                "version": "1.0"
            },
            "links": {
                "self": "/v1/discount-codes/4"
            }
        }

## Ticket Discount Code Collection [/v1/events/{event_identifier}/discount-codes{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]
+ Parameters
    + event_identifier: 1 (string) - identifier or event id of the event. (b8324ae2 is an example of identifier)
    + page%5bsize%5d (optional, integer, `10`) - Maximum number of resources in a single paginated response.
    + page%5bnumber%5d (optional, integer, `2`) - Page number to fetched for the paginated response.
    + sort (optional, string, `code`) - Sort the resources according to the given attribute in ascending order. Append '-' to sort in descending order.
    + filter (optional, string, `[]`) - Filter according to the flask-rest-jsonapi filtering system. Please refer: http://flask-rest-jsonapi.readthedocs.io/en/latest/filtering.html for more.

### Create Ticket Discount Code [POST /v1/discount-codes]
Create a new Discount Code for event. (Only by Co-organizers)

+ Request (application/vnd.api+json)

    + Headers

            Authorization: JWT <Auth Key>

    + Body

            {
              "data": {
                "attributes": {
                  "code": "DC101",
                  "discount-url": "https://my-discount-url.com",
                  "value": "100",
                  "type": "percent",
                  "is-active": "false",
                  "tickets-number": "404",
                  "min-quantity": "0",
                  "max-quantity": "100",
                  "valid-from": "2099-06-18T18:30:00+00:00",
                  "valid-till": "2099-06-24T18:30:00+00:00",
                  "used-for": "ticket"
                },
                "type": "discount-code",
                "relationships": {
                  "event": {
                    "data": {
                      "id": "1",
                      "type": "event"
                    }
                  },
                  "tickets": {
                    "data": [{
                      "id": "1",
                      "type": "ticket"
                    }]
                  }
                }
              }
            }

+ Response 201 (application/vnd.api+json)

        {
            "data": {
                "type": "discount-code",
                "id": 1,
                "attributes": {
                    "discount-url": "https://my-discount-url.com",
                    "deleted-at": null,
                    "used-for": "ticket",
                    "min-quantity": 0,
                    "value": 100,
                    "max-quantity": 100,
                    "valid-till": "2017-06-24T18:30:00+00:00",
                    "is-active": false,
                    "type": "percent",
                    "code": "DC101",
                    "valid-from": "2017-06-18T18:30:00+00:00",
                    "tickets-number": 404,
                    "created-at": "2018-06-26T16:03:33.494021+00:00"
                },
                "relationships": {
                    "event": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/event",
                            "related": "/v1/discount-codes/1/event"
                        }
                    },
                    "tickets": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/tickets",
                            "related": "/v1/discount-codes/1/tickets"
                        }
                    },
                    "marketer": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/marketer",
                            "related": "/v1/discount-codes/1/marketer"
                        }
                    }
                },
                "links": {
                    "self": "/v1/discount-codes/1"
                }
            },
            "links": {
                "self": "/v1/discount-codes/1"
            },
            "jsonapi": {
                "version": "1.0"
            }
        }

### List All Ticket Discount Codes [GET]
Get a list of Discount Codes.

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
          "meta": {
              "count": 1
          },
          "data": [
              {
                  "relationships": {
                      "event": {
                          "links": {
                              "self": "/v1/discount-codes/1/relationships/event",
                              "related": "/v1/discount-codes/1/event"
                          }
                      },
                      "tickets": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/tickets",
                                "related": "/v1/discount-codes/1/tickets"
                            }
                      }
                  },
                  "attributes": {
                      "code": "DC101",
                      "valid-from": "2099-06-18T18:30:00+00:00",
                      "min-quantity": 0,
                      "created-at": "2099-06-20T09:59:23.740772+00:00",
                      "tickets-number": 404,
                      "value": 100,
                      "max-quantity": 100,
                      "is-active": false,
                      "used-for": "ticket",
                      "deleted-at": null,
                      "valid-till": "2099-06-24T18:30:00+00:00",
                      "type": "amount",
                      "discount-url": "https://my-discount-url.com"
                  },
                  "type": "discount-code",
                  "id": 1,
                  "links": {
                      "self": "/v1/discount-codes/1"
                  }
              }
          ],
          "jsonapi": {
              "version": "1.0"
          },
          "links": {
              "self": "/v1/events/1/discount-codes"
          }
         }


## Discount Code Detail [/v1/discount-codes/{discount_code_id}]
+ Parameters
    + discount_code_id: 1 (integer) - ID of the discount code in the form of an integer

### Discount Code Detail [GET]
Get a single discount code.

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
            "data": {
                "relationships": {
                    "event": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/events",
                            "related": "/v1/discount-codes/1/events"
                        }
                    },
                    "tickets": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/tickets",
                            "related": "/v1/discount-codes/1/tickets"
                        }
                    }
                },
                "attributes": {
                    "code": "DC101",
                    "valid-from": "2099-06-18T18:30:00+00:00",
                    "min-quantity": 0,
                    "created-at": "2099-06-27T10:43:20.840012+00:00",
                    "tickets-number": 404,
                    "value": 100,
                    "max-quantity": 100,
                    "is-active": false,
                    "used-for": "ticket",
                    "deleted-at": null,
                    "valid-till": "2099-06-24T18:30:00+00:00",
                    "type": "amount",
                    "discount-url": "https://my-discount-url.com"
                },
                "type": "discount-code",
                "id": 1,
                "links": {
                    "self": "/v1/discount-codes/1"
                }
            },
            "jsonapi": {
                "version": "1.0"
            },
            "links": {
                "self": "/v1/discount-codes/1"
            }
        }


### Update Discount Code [PATCH]
Update a single discount code with `id` (Check permission to edit).

+ `id` (integer) - ID of the record to update **(required)**

+ Request (application/vnd.api+json)

    + Headers

            Authorization: JWT <Auth Key>

    + Body

            {
              "data": {
                "attributes": {
                  "code": "DC101",
                  "discount-url": "https://my-discount-url.com",
                  "value": "50",
                  "type": "percent",
                  "is-active": "false",
                  "tickets-number": "404",
                  "min-quantity": "0",
                  "max-quantity": "100",
                  "valid-from": "2099-06-18T18:30:00+00:00",
                  "valid-till": "2099-06-24T18:30:00+00:00",
                  "used-for": "ticket"
                },
                "type": "discount-code",
                "id": "1"
              }
            }

+ Response 200 (application/vnd.api+json)

        {
          "data": {
            "relationships": {
              "event": {
                "links": {
                  "self": "/v1/discount-codes/1/relationships/events",
                  "related": "/v1/discount-codes/1/events"
                }
              },
              "marketer": {
                "links": {
                    "self": "/v1/discount-codes/1/relationships/marketer",
                    "related": "/v1/discount-codes/1/marketer"
                }
              },
              "tickets": {
                "links": {
                    "self": "/v1/discount-codes/1/relationships/tickets",
                    "related": "/v1/discount-codes/1/tickets"
                }
              }
            },
            "attributes": {
              "code": "DC101",
              "valid-from": "2017-06-18T18:30:00+00:00",
              "min-quantity": 0,
              "created-at": "2017-06-20T09:59:23.740772+00:00",
              "tickets-number": 404,
              "value": 50,
              "max-quantity": 100,
              "is-active": false,
              "deleted-at": null,
              "used-for": "ticket",
              "valid-till": "2017-06-24T18:30:00+00:00",
              "type": "percent",
              "discount-url": "https://my-discount-url.com"
            },
            "type": "discount-code",
            "id": 1,
            "links": {
              "self": "/v1/discount-codes/1"
            }
          },
          "jsonapi": {
            "version": "1.0"
          },
          "links": {
            "self": "/v1/discount-codes/1"
          }
        }

### Delete Discount Code [DELETE]
Delete a single discount code (Check permission to delete).

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
          "meta": {
            "message": "Object successfully deleted"
          },
          "jsonapi": {
            "version": "1.0"
          }
        }

## Get Discount Code Detail using the code [/v1/events/{event_id}/discount-codes/{code}]
+ Parameters
    + code: DC101 (string) - code associated with a discount code. (DC101 is an example of code)
    + event_id: 1 (integer) - ID of the Event in the form of an integer

### Get Discount Code Detail [GET]
Get a single discount code using a code.

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
            "data": {
                "relationships": {
                    "event": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/event",
                            "related": "/v1/discount-codes/1/event"
                        }
                    }
                },
                "attributes": {
                    "code": "DC101",
                    "valid-from": "2099-06-18T18:30:00+00:00",
                    "min-quantity": 0,
                    "created-at": "2099-08-05T23:38:04.449623+00:00",
                    "tickets-number": 404,
                    "value": 100,
                    "max-quantity": 100,
                    "is-active": false,
                    "used-for": "event",
                    "deleted-at": null,
                    "valid-till": "2099-06-24T18:30:00+00:00",
                    "type": "amount",
                    "discount-url": "https://my-discount-url.com"
                },
                "type": "discount-code",
                "id": 1,
                "links": {
                    "self": "/v1/discount-codes/1"
                }
            },
            "jsonapi": {
                "version": "1.0"
            },
            "links": {
                "self": "/v1/discount-codes/1"
            }
        }


## List Discount Codes under a User [/v1/users/{user_id}/discount-codes{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]
+ Parameters
    + user_id: 1 (string) - user id in the form of an integer.
    + page%5bsize%5d (optional, integer, `10`) - Maximum number of resources in a single paginated response.
    + page%5bnumber%5d (optional, integer, `2`) - Page number to fetched for the paginated response.
    + sort (optional, string, `code`) - Sort the resources according to the given attribute in ascending order. Append '-' to sort in descending order.
    + filter (optional, string, `[]`) - Filter according to the flask-rest-jsonapi filtering system. Please refer: http://flask-rest-jsonapi.readthedocs.io/en/latest/filtering.html for more.

### List All Discount Codes under a User [GET]
Get a list of Discount Codes.

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
            "meta": {
                "count": 1
            },
            "data": [
                {
                    "relationships": {
                        "event": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/event",
                                "related": "/v1/discount-codes/1/event"
                            }
                        },
                        "tickets": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/tickets",
                                "related": "/v1/discount-codes/1/tickets"
                            }
                        }
                    },
                    "attributes": {
                        "code": "DC101",
                        "valid-from": "2099-06-18T18:30:00+00:00",
                        "min-quantity": 0,
                        "created-at": "2099-08-05T23:38:04.449623+00:00",
                        "tickets-number": 404,
                        "value": 100,
                        "max-quantity": 100,
                        "is-active": false,
                        "used-for": "event",
                        "deleted-at": null,
                        "valid-till": "2099-06-24T18:30:00+00:00",
                        "type": "amount",
                        "discount-url": "https://my-discount-url.com"
                    },
                    "type": "discount-code",
                    "id": 1,
                    "links": {
                        "self": "/v1/discount-codes/1"
                    }
                }
            ],
            "jsonapi": {
                "version": "1.0"
            },
            "links": {
                "self": "/v1/users/1/discount-codes"
            }
        }

## List Discount Codes under a Ticket [/v1/tickets/{ticket_id}/discount-codes{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]
+ Parameters
    + ticket_id: 1 (string) - user id in the form of an integer.
    + page%5bsize%5d (optional, integer, `10`) - Maximum number of resources in a single paginated response.
    + page%5bnumber%5d (optional, integer, `2`) - Page number to fetched for the paginated response.
    + sort (optional, string, `code`) - Sort the resources according to the given attribute in ascending order. Append '-' to sort in descending order.
    + filter (optional, string, `[]`) - Filter according to the flask-rest-jsonapi filtering system. Please refer: http://flask-rest-jsonapi.readthedocs.io/en/latest/filtering.html for more.

### List All Discount Codes under a Ticket [GET]
Get a list of Discount Codes applied on a given ticket.

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
            "data": [
                {
                    "type": "discount-code",
                    "relationships": {
                        "tickets": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/tickets",
                                "related": "/v1/discount-codes/1/tickets"
                            }
                        },
                        "marketer": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/marketer",
                                "related": "/v1/discount-codes/1/marketer"
                            }
                        },
                        "event": {
                            "links": {
                                "self": "/v1/discount-codes/1/relationships/event",
                                "related": "/v1/discount-codes/1/event"
                            }
                        }
                    },
                    "attributes": {
                        "value": 100,
                        "created-at": "2099-06-26T16:03:33.494021+00:00",
                        "tickets-number": 404,
                        "code": "DC101",
                        "used-for": "ticket",
                        "is-active": false,
                        "max-quantity": 100,
                        "discount-url": "https://my-discount-url.com",
                        "type": "amount",
                        "min-quantity": 0,
                        "valid-from": "2099-06-18T18:30:00+00:00",
                        "valid-till": "2099-06-24T18:30:00+00:00",
                        "deleted-at": null
                    },
                    "id": 1,
                    "links": {
                        "self": "/v1/discount-codes/1"
                    }
                }
            ],
            "links": {
                "self": "/v1/tickets/1/discount-codes"
            },
            "meta": {
                "count": 1
            },
            "jsonapi": {
                "version": "1.0"
            }
        }

## Get Discount Code Detail of an Event [/v1/events/{event_identifier}/discount-code]
+ Parameters
    + event_identifier: 1 (string) - identifier or event id of the event. (b8324ae2 is an example of identifier)

### Get Discount Code Detail of an Event [GET]
Get a single discount code.

+ Request

    + Headers

            Accept: application/vnd.api+json

            Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

        {
            "data": {
                "relationships": {
                    "event": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/event",
                            "related": "/v1/discount-codes/1/event"
                        }
                    },
                    "events": {
                        "links": {
                            "self": "/v1/discount-codes/1/relationships/events",
                            "related": "/v1/discount-codes/1/events"
                        }
                    }
                },
                "attributes": {
                    "code": "DC101",
                    "valid-from": "2099-06-18T18:30:00+00:00",
                    "min-quantity": 0,
                    "created-at": "2099-08-05T23:38:04.449623+00:00",
                    "tickets-number": 404,
                    "value": 100,
                    "max-quantity": 100,
                    "is-active": false,
                    "used-for": "event",
                    "deleted-at": null,
                    "valid-till": "2099-06-24T18:30:00+00:00",
                    "type": "amount",
                    "discount-url": "https://my-discount-url.com"
                },
                "type": "discount-code",
                "id": 1,
                "links": {
                    "self": "/v1/discount-codes/1"
                }
            },
            "jsonapi": {
                "version": "1.0"
            },
            "links": {
                "self": "/v1/discount-codes/1"
            }
        }
